﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CardInChina.Common.Tool
{
    public class DataCache
    {
        private IDictionary<string, object> data = new Dictionary<string, object>();

        public T GetData<T>(string key, GetDataAction<T> act)
        {
            if (data.ContainsKey(key))
            {
                return (T)data[key];
            }
            else
            {
                var result = act();
                data.Add(key, result);
                return result;
            }
        }
    }

    public delegate T GetDataAction<T>();
}
